package com.ma4567.remotecontroller.SmallTools.Calendar;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.ma4567.remotecontroller.MysqlHelper.CalendarTodo;
import com.ma4567.remotecontroller.MysqlHelper.TableRequestLog;
import com.ma4567.remotecontroller.RemoteControllerApplication;
import com.ma4567.remotecontroller.ffmpegManager.ffmpegController;
import com.ma4567.remotecontroller.util.CustomRespone;
import com.ma4567.remotecontroller.util.Matters;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;
import java.util.ArrayList;

@CrossOrigin
@RestController
public class DeleteTodo {
    @RequestMapping(value = "/api/deleteTodo", method = RequestMethod.GET)
    public String GetTodoList(HttpServletRequest request,
                              @RequestParam("cookie") String Cookie,
                              @RequestParam("id") int id) throws SQLException {
        ffmpegController.StopStream();
        TableRequestLog.AddLog("Delete Todo item " + id, Cookie, request.getRemoteAddr());
        if(!RemoteControllerApplication.userManager.JudgeCookie(Cookie)){//鉴cookie
            return JSONObject.toJSONString(new CustomRespone(1), SerializerFeature.PrettyFormat);
        }
        else{
            CalendarTodo.deleteMatter(id);
            return JSONObject.toJSONString(new CustomRespone(0), SerializerFeature.PrettyFormat);
        }
    }
}
